using Gtk;

namespace Atlantis
{
    public class Application : Presenter<IShellView>
    {
        private IWorkspace documentWorkspace;
        private IWorkspace viewsWorkspace;

        public Application(Registry registry){
            base(registry);
        }

		/*
			test
		*/
        protected override void OnViewSet(){
			stderr.printf("in Application.OnViewSet");
            
            // Initialize the main document arria
            this.documentWorkspace = this.View.DocumentWorkspace;
            this.documentWorkspace.SelectedSmartPartChanged.connect(OnSelectedSmartPartChanged);
            
            this.viewsWorkspace = this.View.ViewsWorkspace;
            
            //
            // Initialize the welcome page
            //
            var browser = Registry.Get<BrowserView>();
            this.documentWorkspace.Add(browser);
            browser.Open("http://creatinghidalgo.blogspot.com/");
            
            //
            // Initialize the project explorer
            //
            var projectExplorer = Registry.Get<ProjectExplorer>();
            this.viewsWorkspace.Add(projectExplorer);
        }
        
        private void OnSelectedSmartPartChanged(IWorkspace sender, GLib.Object selectedSmartPart){
			stderr.printf("Application.OnSelectedSmartPartChanged");
			if (selectedSmartPart is DocumentView){
				DocumentView view = selectedSmartPart as DocumentView;
				var service = Registry.Get<IDocumentService>();
				service.SelectedDocument = view.Document;
				stderr.printf("service.SelectedDocument = view.Document");
			}
		}
      
        public int Run(string[] args){
            Gtk.init(ref args);
            var view = Registry.Get<IShellView>();
            view.Presenter = this;
            this.View = view;
            view.Show();
            
            Gtk.main();
            return 0;   
        }
    }
}
